<?php
namespace app\index\controller;
use app\index\model\Wx;
use think\Controller;

class Auths extends Controller
{
    //授权
    public function index()
    {
        $wx = new Wx();
        return $wx->openauths(config('httpurl'));
    }

    //微信授权回调
    public function wxBack()
    {
        $wx = new Wx();
        $appid = $wx->configs['APPID'];
        $secret = $wx->configs['APPSECRET'];
        $code = input('param.code');
		if(session($code)){
			$userInfo = json_decode(session($code),true);
		}else{
		$token = $wx->getToken($appid,$secret,$code);
        //$userInfo = $wx->getUserInfo($token['access_token'],$token['openid']);
		$userInfo['headimgurl'] = "";
		$userInfo['openid'] = $token['openid'];
		}
        
		session($code,json_encode($userInfo));
        session('head',$userInfo['headimgurl']);
        session('pfopenid',$userInfo['openid']);
        $this->redirect('Makescore/matching');
    }
}